package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx.goods.bo.GoodsListBo;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.category.CategoryService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 创建日期: 2022/05/08 19:13
 *
 * @author JinLu Zhou
 */
@RestController
@RequestMapping("wx/goods")
public class WXGoodsController {
    @Autowired
    GoodsService goodsService;
    @Autowired
    CategoryService categoryService;

    @RequestMapping("count")
    public BaseRespVo index() {

        return goodsService.queryAllGoodsType();
    }

    @RequestMapping("category")
    public BaseRespVo category(Integer id) {

        return categoryService.selectL2Category(id);
    }

    @RequestMapping("list")
    public BaseRespVo list(GoodsListBo goodsListBo) {

        return categoryService.selectGoodsList(goodsListBo);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        //添加足跡
        Subject subject = SecurityUtils.getSubject();
        if(subject.isAuthenticated()){
            Integer principal = (Integer) subject.getPrincipal();
            categoryService.insertFootprint(principal,id);
        }
        return categoryService.selectGoodsDetailList(id);
    }

    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        return categoryService.selectRelated(id);
    }
}
